package com.woniuxy.springmvcannotation;

import com.woniuxy.springnvcannotation.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author linke
 * @version 1.0
 * @className: ForwardController
 * @description: 请求转发
 * @date 2021/11/13 18:26
 * @Controller 将控制器交给spring容器管理 表示要跳页面
 * @RequestMapping 定义页面请求路径，与执行该路径请求的 方法之间的映射关系
 */
@RequestMapping("/forward")
@Controller
public class ForwardController {
    /**
     * *String 做请求转发forward 后一定要是完整路径！！！
     * return “for**ard:/sys/login02”;*
     *
     * @param model
     * @param userBean
     * @param sessionID 返回Cookie内容
     * @param userAgent 返回请求头的内容
     * @return 返回的字符串，就是需要跳转的页面
     */
    @RequestMapping(value = "/login")
    public String login(Model model, UserBean userBean,
                        @CookieValue("JSESSIONID") String sessionID, @RequestHeader("User-Agent") String userAgent){
        System.out.println(userBean);//UserBean(id=null, userName=null, loginName=222, password=2e22, age=null)
        System.out.println(sessionID);//F999234CFD91AEDB9B74A38A49779395
        System.out.println(userAgent);//Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

        userBean.setUserName("张三");
        model.addAttribute("user",userBean);
        return "forward:/forward/login02";
    }

    @RequestMapping("/login02")
    public String login02(UserBean userBean){
        System.out.println(userBean);//UserBean(id=null, userName=null, loginName=222, password=2e22, age=null)
        return "sysmag/main";
    }
}
